package com.wc.AlgoOJ_homework.AlgoOJ_test3.E_图片用纸板;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 19:20
 * @description http://43.138.190.70:8888/p/985?tid=65e5dab127489dab814f76e2
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] s = new int[N];
    static int n, t;
    static long x, c;

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            c = sc.nextLong();
            for (int i = 1; i <= n; i++) s[i] = sc.nextInt();
//            long a = 4L * n;
//            long b = 0;
//            long c = 0;
//
//            for (int i = 1; i <= n; i++) {
//                b += 4L * s[i];
//                c += (long) s[i] * s[i];
//            }
//            c -= x;
//            out.println(getW(a, b, c));
            long l = 1, r = (long) 1e9;
            while (l < r) {
                long mid = l + r >> 1;
                if (check(mid)) r = mid;
                else l = mid + 1;
            }
            out.println(l);
        }
        out.flush();
    }

    static boolean check(long mid) {
        long res = 0;
        for (int i = 1; i <= n; i++) {
            res += (s[i] + 2 * mid) * (s[i] + 2 * mid);
            if (res >= c) {
                return true;
            }
        }
        return false;
    }

//    static String getW(long a, long b, long c) {
//        BigInteger A = new BigInteger(String.valueOf(a));
//        BigInteger B = new BigInteger(String.valueOf(-b));
//        BigInteger C = new BigInteger(String.valueOf(-c));
//        // (-b + sqrt(b * b - 4 * a * c) / (2 * a)
//        BigInteger res = (B.add((B.multiply(B).add(new BigInteger("4").multiply(A).multiply(C))).sqrt()).divide(new BigInteger("2").multiply(A)));
//        return res.toString();
//    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}